package linz

fun main() {
    val map = mapOf("key" to 23, "key2" to 34, "key3" to 45)
    val mapOf2 = mapOf(Pair("key", 23), Pair("key2", 45))
    val mutableMap = mutableMapOf("key" to 23, "key2" to 34, "key3" to 45)



    //todo 获取 value 的三种方法
    println(map["key"])
    println(map["xxx"]) // 输出 null

    println(map.getOrDefault("key", -1))

    println(map.getOrElse("key") { -1 })

    println()


    //todo map 遍历的4种方式
    map.forEach{
        println("Key:${it.key} value:${it.value}")
    }
    println()

    map.forEach { key, value ->
        println("Key:${key} value:${value}")
    }

    for (entry in map) {
        println("Key:${entry.key} value:${entry.value}")
    }

    //todo map 简单操作
    mutableMap += "AAA" to(111)
    mutableMap -= "key"

    //没有就往里面存
    val r = mutableMap.getOrPut("FFF") { 555 }
    println(r)  // 555
    println(mutableMap["FFF"]) // output 555

    listOf("SZ","SH","BJ","GZ").zip(listOf(1,2,3,4)).toMap().map {
        println("Key :${it.key}, value: {${it.value}}")
    }


}